home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / activate.zip / ACT-DOS.C next >
Text File  |  1992-12-04  |  2KB  |  66 lines

  1. /*
  2.  *  Activate.c (v1.01)
  3.  *
  4.  *  MS-DOS / TURBO C++ specific routines for accessing 1st sector of HD
  5.  *
  6.  */
  7.  
  8.  
  9. /*
  10.  *  Reads in Cyl 0, Side 0, Sector 1 from each physical hard disk into
  11.  *  buffer (global variable) and extracts partition table info from the
  12.  *  sector (partn tbl starts at 0x1BE, 4 entries of 0x10 bytes plus a 2
  13.  *  byte signature at end. Returns 0 if read OK, non-zero otherwise.
  14.  *
  15.  */
  16.  
  17. int read_partition_table(partn, drive)
  18. partition_table *partn;
  19. int drive;
  20. {
  21.   int status;
  22.  
  23.   status = biosdisk(_DISK_READ, drive, 0, 0, 1, 1, buffer);
  24.   memmove(partn, (buffer + 0x1BE), sizeof(partition_table));
  25.   return status;
  26. }
  27.  
  28.  
  29. /*
  30.  *  Does the reverse of read_partition_table() - writes a new partition
  31.  *  table into the relevent bit of buffer (the last 74 bytes) and writes
  32.  *  the whole 512 bytes to the 1st sector of the specified Hard Drive
  33.  *
  34.  */
  35.  
  36.  
  37. int write_partition_table(partn, drive)
  38. partition_table partn;
  39. int drive;
  40. {
  41.   int status;
  42.  
  43.   memmove((buffer + 0x1BE), &partn, sizeof(partition_table));
  44.   status = biosdisk(_DISK_WRITE, drive, 0, 0, 1, 1, buffer);
  45.   return status;
  46. }
  47.  
  48.  
  49. /*
  50.  * Determines how many Hard drives the BIOS is aware of by trying to read
  51.  * the Master Boot sector of each Hard drive starting from 0x80 (1st disk)
  52.  * contines to read drives (0x81, 0x82, etc) until it receives an error,
  53.  * after which it assumes that all physical drives have been read.
  54.  *
  55.  * Returns number of drives which it has detected.
  56.  *
  57.  */
  58.  
  59. int determine_number_of_drives()
  60. {
  61.   int drive = 0x80;
  62.  
  63.   while(!biosdisk(_DISK_READ, drive++, 0, 0, 1, 1, NULL));
  64.   return drive - 0x81;
  65. }
  66.